import java.util.Scanner;
import java.util.ArrayList;
public class Main5 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList strlist =new ArrayList();
		ArrayList strList1 = new ArrayList();
		String str = sc.next();
		while(!str.equals("!!end!!")){
			strlist.add(str);
			str = sc.next();
		}
		String str1 = sc.next();
		String str2 = sc.next();
		String str3 = sc.next();
		
		strlist.add("end");
		strlist.add(0, "begin");
		System.out.println(strlist);
		System.out.println(strlist.contains(str1));
		System.out.println(strlist.indexOf(str1));
		System.out.println(strlist.lastIndexOf(str1));
		System.out.println(strlist.get(0));
		strlist.remove(0);
		System.out.println(strlist);
		
		strlist.set(1, str2);
		System.out.println(strlist);
		
		for(int i=0;i<strlist.size();i++){
			String str4=(String)strlist.get(i);
			if(str4.indexOf(str3)!=-1){
				strList1.add(str4);
			}
		System.out.println(strList1);
		strlist.remove(str1);
		System.out.println(strlist);
		strlist.clear();
		System.out.println(strlist+","+strlist.size()+","+strlist.isEmpty());
		}
	}

}
